package com.dt76.smallloanbackenduser.controller.xm;

import com.dt76.smallloanbackenduser.pojo.xm.BeforeOrderQuery;
import com.dt76.smallloanbackenduser.remote.xm.BeforeOrderRemote;
import com.dt76.smallloanbackenduser.remote.xm.HLoanProductsRemote;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/xm")
public class beforeOrderController {

    @Resource
    private BeforeOrderRemote beforeOrderRemote;
    @Resource
    private HLoanProductsRemote hLoanProductsRemote;

    @GetMapping("/firstCheck")
    public String qryConditionPageAll(Model model, Integer currentPageNo, BeforeOrderQuery beforeOrderQuery) {
        //页面
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }

        if (beforeOrderQuery.getQueryBoTypeList() ==  null) {
            String[] boTyList = {"等待初审","初审通过","初审驳回","初审拒绝"};
            beforeOrderQuery.setQueryBoTypeList(boTyList);
        }
        //System.out.println(beforeOrderQuery.toString());
        //查询条件
        model.addAttribute("beforeOrderQuery", beforeOrderQuery);
        //返回贷款类型
        model.addAttribute("LoanTypes", hLoanProductsRemote.qryAllHLoanProduct());
        //System.out.println(hLoanProductsRemote.qryAllHLoanProduct());
        //所有订单
        model.addAttribute("beforeOrders", beforeOrderRemote.qryPageConditionAll(currentPageNo, beforeOrderQuery).getRows());
        System.out.println(beforeOrderRemote.qryPageConditionAll(currentPageNo, beforeOrderQuery).getRows());
        //页面
        model.addAttribute("page", beforeOrderRemote.qryPageConditionAll(currentPageNo, beforeOrderQuery));
        return "pages/xm/firstCheck";
    }

    @RequestMapping("/secondCheck")
    public String qryConditionPageAll2(Model model, Integer currentPageNo, BeforeOrderQuery beforeOrderQuery) {
        //页面
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }

        if (beforeOrderQuery.getQueryBoTypeList() ==  null) {
            String[] boTyList = {"初审通过","复审通过","复审驳回","复审拒绝"};
            beforeOrderQuery.setQueryBoTypeList(boTyList);
        }
        System.out.println(beforeOrderQuery.toString());
        //查询条件
        model.addAttribute("beforeOrderQuery", beforeOrderQuery);
        //返回贷款类型
        model.addAttribute("LoanTypes", hLoanProductsRemote.qryAllHLoanProduct());
        //所有订单
        model.addAttribute("beforeOrders", beforeOrderRemote.qryPageConditionAll2(currentPageNo, beforeOrderQuery).getRows());
        //页面
        model.addAttribute("page", beforeOrderRemote.qryPageConditionAll2(currentPageNo, beforeOrderQuery));
        return "pages/xm/secondCheck";

    }


}
